package com.wx.sakura.service;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @ClassName ThreadTest
 * @Description: TODO
 * @Author 86185
 * @Date 2020/8/19
 * @Version V1.0
 **/
public class ThreadTest {
    public static void main(String[] args) {
        ThreadLocal a = new ThreadLocal();
        ExecutorService executor = Executors.newFixedThreadPool(3);
        String param1 ="aaa";
        a.set(param1);
        List<String> list = new LinkedList<String>(){{
            add("a");
            add("b");
            add("c");
        }};
        List<String> nList = new ArrayList();
        list.forEach(s->CompletableFuture.runAsync(()->{
            try {
                String b = a.get().toString();
                System.out.println("b的值为"+b);
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            nList.add(s.toUpperCase());
        }, executor).join());

        System.out.println(nList);//[HI, DIDI, HELLO]
    }
}
